package com.ruoyi.system.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.domain.FxyFinancialAccountingCategoryDetails;
import com.ruoyi.system.service.IFxyFinancialAccountingCategoryDetailsService;
import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping({"/details"})
public class FxyFinancialAccountingCategoryDetailsController extends BaseController {
    @Autowired
    private IFxyFinancialAccountingCategoryDetailsService fxyFinancialAccountingCategoryDetailsService;

    public FxyFinancialAccountingCategoryDetailsController() {
    }

    @RequiresPermissions({"system:details:list"})
    @GetMapping({"/list"})
    public TableDataInfo list(FxyFinancialAccountingCategoryDetails fxyFinancialAccountingCategoryDetails) {
        this.startPage();
        List<FxyFinancialAccountingCategoryDetails> list = this.fxyFinancialAccountingCategoryDetailsService.selectFxyFinancialAccountingCategoryDetailsList(fxyFinancialAccountingCategoryDetails);
        return this.getDataTable(list);
    }

    @RequiresPermissions({"system:details:export"})
    @Log(
            title = "辅助核算类别明细列",
            businessType = BusinessType.EXPORT
    )
    @PostMapping({"/export"})
    public void export(HttpServletResponse response, FxyFinancialAccountingCategoryDetails fxyFinancialAccountingCategoryDetails) {
        List<FxyFinancialAccountingCategoryDetails> list = this.fxyFinancialAccountingCategoryDetailsService.selectFxyFinancialAccountingCategoryDetailsList(fxyFinancialAccountingCategoryDetails);
        ExcelUtil<FxyFinancialAccountingCategoryDetails> util = new ExcelUtil(FxyFinancialAccountingCategoryDetails.class);
        util.exportExcel(response, list, "辅助核算类别明细列数据");
    }

    @Log(
            title = "供应商",
            businessType = BusinessType.IMPORT
    )
    @RequiresPermissions({"system:details:import"})
    @PostMapping({"/importData"})
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
        ExcelUtil<FxyFinancialAccountingCategoryDetails> util = new ExcelUtil(FxyFinancialAccountingCategoryDetails.class);
        List<FxyFinancialAccountingCategoryDetails> userList = util.importExcel(file.getInputStream());
        String operName = SecurityUtils.getUsername();
        String message = this.fxyFinancialAccountingCategoryDetailsService.importUser(userList, updateSupport, operName);
        return this.success(message);
    }

    @PostMapping({"/importTemplate"})
    public void importTemplate(HttpServletResponse response) throws IOException {
        ExcelUtil<FxyFinancialAccountingCategoryDetails> util = new ExcelUtil(FxyFinancialAccountingCategoryDetails.class);
        util.importTemplateExcel(response, "供应商数据");
    }

    @RequiresPermissions({"system:details:query"})
    @GetMapping({"/{id}"})
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return this.success(this.fxyFinancialAccountingCategoryDetailsService.selectFxyFinancialAccountingCategoryDetailsById(id));
    }

    @RequiresPermissions({"system:details:add"})
    @Log(
            title = "辅助核算类别明细列",
            businessType = BusinessType.INSERT
    )
    @PostMapping
    public AjaxResult add(@RequestBody FxyFinancialAccountingCategoryDetails fxyFinancialAccountingCategoryDetails) {
        return this.toAjax(this.fxyFinancialAccountingCategoryDetailsService.insertFxyFinancialAccountingCategoryDetails(fxyFinancialAccountingCategoryDetails));
    }

    @RequiresPermissions({"system:details:edit"})
    @Log(
            title = "辅助核算类别明细列",
            businessType = BusinessType.UPDATE
    )
    @PutMapping
    public AjaxResult edit(@RequestBody FxyFinancialAccountingCategoryDetails fxyFinancialAccountingCategoryDetails) {
        return this.toAjax(this.fxyFinancialAccountingCategoryDetailsService.updateFxyFinancialAccountingCategoryDetails(fxyFinancialAccountingCategoryDetails));
    }

    @RequiresPermissions({"system:details:remove"})
    @Log(
            title = "辅助核算类别明细列",
            businessType = BusinessType.DELETE
    )
    @DeleteMapping({"/{ids}"})
    public AjaxResult remove(@PathVariable Long[] ids) {
        return this.toAjax(this.fxyFinancialAccountingCategoryDetailsService.deleteFxyFinancialAccountingCategoryDetailsByIds(ids));
    }
}

